package cn.yangliu.gennerator;

import cn.yangliu.bean.ProjectSetting;
import cn.yangliu.source.*;
import com.intellij.util.concurrency.FutureResult;

import java.util.concurrent.Future;

public class GeneratorHandler {

    private EntityGenerator entityGenerator;
    private MapperGenerator mapperGenerator;
    private ServiceImplGenerator serviceImplGenerator;
    private ControllerGenerator controllerGenerator;
    private XmlGenerator xmlGenerator;

    {
        entityGenerator = new EntityGenerator();
        mapperGenerator = new MapperGenerator();
        serviceImplGenerator = new ServiceImplGenerator();
        controllerGenerator = new ControllerGenerator();
        xmlGenerator = new XmlGenerator();

    }

    public Future<Boolean> doGenerator(ProjectSetting projectSetting, EntitySource entitySource, MapperSource mapperSource, XmlSource xmlSource,
                                       ServiceImplSource serviceImplSource, ControllerSource controllerSource) {

        entityGenerator.generate(entitySource);
        mapperGenerator.generate(mapperSource);
        xmlGenerator.generate(xmlSource);
        if (projectSetting.getCreateService()) {
            serviceImplGenerator.generate(serviceImplSource);
        }

        if (projectSetting.getCreateController()) {
            controllerGenerator.generate(controllerSource);
        }
        return new FutureResult<>(true);

    }

}
